package com.yf.Utils;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author chentianwei
 * @date 2024-07-31 17:23
 * @description 分页数据处理
 */
public class PageUtil {

    /**
     * Page 数据处理，预防redis反序列化报错
     */
    public static Map<String,Object> toPage(IPage<?> page) {
        Map<String,Object> map = new LinkedHashMap<>(2);
        map.put("content",page.getRecords());
        map.put("totalElements",page.getTotal());
        return map;
    }

    /**
     * 自定义分页
     */
    public static Map<String,Object> toPage(Object object, Object totalElements) {
        Map<String,Object> map = new LinkedHashMap<>(2);
        map.put("content",object);
        map.put("totalElements",totalElements);
        return map;
    }

}
